﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Web.Mvc;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Models;
using Prodma.DataAccess.Helper.Enumerators;

namespace Prodma.DataAccess.DataService.ListService
{
    public static class ParentMenuList
    {

        private static DataContext context = new DataContext();

        public static SelectList GetList(int location)
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from menu in context.tb_Menu
                            where menu.tb_State.Id == stateId &&
                                  menu.tb_MenuLocation.Id == location &&
                                  menu.ParentId == 0
                            select menu);


                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value");

                return selectList;
            }
        }
        public static SelectList GetList(int location, int? id)
        {
            int stateId = Convert.ToInt32(State.Active);
            DataContext context = new DataContext();
            using (context)
            {
                var list = (from menu in context.tb_Menu
                            where menu.tb_State.Id == stateId &&
                                  menu.tb_MenuLocation.Id == location &&
                                  menu.ParentId == 0
                            select menu);


                SelectList selectList = new SelectList(list.ToDictionary(x => x.Id, z => z.Name), "Key", "Value", id);

                return selectList;
            }
        }
    }
}
